﻿<Window x:Class="ULSDeobfuscator.EditColorRuleWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:ULSDeobfuscator="clr-namespace:ULSDeobfuscator"
        xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:MvvmHelpers="clr-namespace:Elca.MvvmHelpers"
        xmlns:DropDownCustomColorPicker="clr-namespace:DropDownCustomColorPicker" mc:Ignorable="d" 
        d:DataContext="{d:DesignInstance Type=ULSDeobfuscator:EditColorRuleViewModel}"
        d:DesignHeight="600" d:DesignWidth="500"
        Title="{Binding Title, Mode=OneTime}" 
        Left="{Binding WindowLeft, Mode=TwoWay}"
        Top="{Binding WindowTop, Mode=TwoWay}"
        MvvmHelpers:LifetimeEvent.Loaded ="{Binding LoadCommand}" 
        ShowInTaskbar="False">

    <!-- Setting SizeToContent="Height" messes badly with the automatic widths adujstment within the items control. Don't know why... -->

    <Window.Resources>

        <CollectionViewSource x:Key="ProcessesListSource"
                              Source="{Binding ProcessesList}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="ItemName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource x:Key="AreasListSource"
                              Source="{Binding AreasList}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="ItemName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource x:Key="CategoriesListSource"
                              Source="{Binding CategoriesList}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="ItemName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource x:Key="LevelsListSource"
                              Source="{Binding LevelsList}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="ItemName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource x:Key="EventsListSource"
                              Source="{Binding EventsList}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="ItemName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

    </Window.Resources>

    <ScrollViewer Margin="5"
                  VerticalScrollBarVisibility="Auto">

        <Grid Margin="5">
            <Grid.RowDefinitions>
                <!-- 0: explanation -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 2: Rule name -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 4: process label -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <!-- 6: processes list -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 8: area label -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <!-- 10: areas list -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 12: Category label -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <!-- 14: Categories list -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 16: Level label -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <!-- 18: Levels list -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 20: Event ID label -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <!-- 22: Event IDs list -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 24: Message filter -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 26: Correlation filter-->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <!-- 28: Multi-line -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <!-- 30: annotation -->
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="10"/>
                <!-- 32: Foreground / BackgroundColor -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <!-- 34:  Sample text -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <!-- 36: Rule persistence -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <!-- 38: OK/Cancel -->
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <!-- 0: explanation -->
            <TextBlock Grid.ColumnSpan="3">
            Define the conditions to meet in order to set the log entry color:
            </TextBlock>

            <!-- 2: rule name -->
            <TextBlock VerticalAlignment="Center"
                   Grid.Row="2">
            Rule Name:
            </TextBlock>

            <TextBox Text="{Binding Rule.Name, Mode=TwoWay}"
                 Grid.Row="2" Grid.Column="2"
                 />

            <!-- 4: Process label -->
            <TextBlock Text="If the process is any one of:"
                   Grid.Row="4" Grid.ColumnSpan="3"/>
            <!-- 6: processes list -->
            <Border Grid.Row="6" Grid.ColumnSpan="3" 
                BorderBrush="Gray" BorderThickness="1">
                <ScrollViewer MaxHeight="100"
                      VerticalScrollBarVisibility="Auto">

                    <ItemsControl ItemsSource="{Binding Source={StaticResource ProcessesListSource}, Mode=OneTime}"
                          BorderBrush="Gray" BorderThickness="1"
                          MvvmHelpers:ItemsControlSizeObserver.Widths="{Binding ProcessItemsWidth}"
                          MvvmHelpers:ItemsControlSizeObserver.IsWidthReady="{Binding AreProcessItemsWidthReady, Mode=TwoWay}"
                          >

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ScrollViewer>
            </Border>

            <!-- 8: Areas label-->
            <TextBlock Text="And the area is any one of:"
                   Grid.Row="8" Grid.ColumnSpan="3" />

            <!-- 10: Areas list -->
            <Border Grid.Row="10" Grid.ColumnSpan="3" 
                BorderBrush="Gray" BorderThickness="1">
                <ScrollViewer MaxHeight="100"
                          
                          VerticalScrollBarVisibility="Auto">

                    <ItemsControl ItemsSource="{Binding Source={StaticResource AreasListSource}, Mode=OneTime}"
                          MvvmHelpers:ItemsControlSizeObserver.Widths="{Binding AreaItemsWidth}"
                          MvvmHelpers:ItemsControlSizeObserver.IsWidthReady="{Binding AreAreaItemsWidthReady, Mode=TwoWay}"
                          >

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ScrollViewer>
            </Border>
            <!-- 12: Category label -->
            <TextBlock Text="And the category is any one of:"
                   Grid.Row="12" />

            <!-- 14: Categories list -->
            <Border Grid.Row="14" Grid.ColumnSpan="3" 
                BorderBrush="Gray" BorderThickness="1"
>
                <ScrollViewer MaxHeight="100"
                          VerticalScrollBarVisibility="Auto">
                    <ItemsControl ItemsSource="{Binding Source={StaticResource CategoriesListSource}, Mode=OneTime}"
                          MvvmHelpers:ItemsControlSizeObserver.Widths="{Binding CategoryItemsWidth}"
                          MvvmHelpers:ItemsControlSizeObserver.IsWidthReady="{Binding AreCategoryItemsWidthReady, Mode=TwoWay}"
                          >

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ScrollViewer>
            </Border>
            <!-- 16: Level label -->
            <TextBlock Text="And the level is any one of:"
                   Grid.Row="16" />

            <!-- 18: Levels list -->
            <Border Grid.Row="18" Grid.ColumnSpan="3" 
                BorderBrush="Gray" BorderThickness="1">
                <ScrollViewer MaxHeight="100"
                      VerticalScrollBarVisibility="Auto">

                    <ItemsControl ItemsSource="{Binding Source={StaticResource LevelsListSource}, Mode=OneTime}"
                      BorderBrush="Gray" BorderThickness="1"
                      MvvmHelpers:ItemsControlSizeObserver.Widths="{Binding LevelItemsWidth}"
                      MvvmHelpers:ItemsControlSizeObserver.IsWidthReady="{Binding AreLevelItemsWidthReady, Mode=TwoWay}"
                      >

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ScrollViewer>
            </Border>

            <!-- 20: Event ID label -->
            <TextBlock Text="And the event ID is any one of:"
                   Grid.Row="20" />

            <!-- 22: Event IDs list -->
            <Border Grid.Row="22" Grid.ColumnSpan="3" 
                BorderBrush="Gray" BorderThickness="1">
                <ScrollViewer MaxHeight="100"
                      VerticalScrollBarVisibility="Auto">

                    <ItemsControl ItemsSource="{Binding Source={StaticResource EventsListSource}, Mode=OneTime}"
                      BorderBrush="Gray" BorderThickness="1"
                      MvvmHelpers:ItemsControlSizeObserver.Widths="{Binding EventIDItemsWidth}"
                      MvvmHelpers:ItemsControlSizeObserver.IsWidthReady="{Binding AreEventIDItemsWidthReady, Mode=TwoWay}"
                      >

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ScrollViewer>
            </Border>

            <!-- 24: Message filter -->
            <TextBlock VerticalAlignment="Center"
                   Grid.Row="24">
            And the message contains:
            </TextBlock>
            <TextBox Text="{Binding Rule.Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                 Grid.Row="24" Grid.Column="2"
                />

            <!-- 26: Correlation filter-->
            <TextBlock VerticalAlignment="Center"
                       Grid.Row="26">
            And the correlation ID contains:
            </TextBlock>
            <TextBox Text="{Binding Rule.Correlation, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                 Grid.Row="26" Grid.Column="2"
                />

            <!-- 28: Multi-line -->
            <CheckBox IsChecked="{Binding Rule.IsMultiLine,Mode=TwoWay}"
                  Grid.Row="28" Grid.ColumnSpan="3">
                And the log entry spans multiple lines
            </CheckBox>

            <!-- 30: Annotation -->
            <CheckBox IsChecked="{Binding Rule.HasAnnotation,Mode=TwoWay}"
                  Grid.Row="30" Grid.ColumnSpan="3">
                And the log entry is annotated
            </CheckBox>

            <!-- 32: Foreground / Background Color -->
            <Grid Grid.Row="32" Grid.ColumnSpan="3">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="20" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <!-- 0: explanation -->
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <!-- 2: foreground color -->
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <!-- 4: background color -->
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <!-- 0: explanation -->
                <TextBlock Grid.ColumnSpan="3">Then:</TextBlock>
                <!-- 2: foreground -->
                <CheckBox IsChecked="{Binding IsForegroundColorManaged, Mode=TwoWay}"
                      Grid.Row="2"
                      VerticalAlignment="Center">
                    Set the foreground color to:
                </CheckBox>
                <DropDownCustomColorPicker:CustomColorPicker 
                Grid.Row="2" Grid.Column="2"
                SelectedColor="{Binding ForegroundColor, Mode=TwoWay}"
                Width="50"
                HorizontalAlignment="Left"/>
                <!-- 4: background color -->
                <CheckBox IsChecked="{Binding IsBackgroundColorManaged, Mode=TwoWay}"
                      Grid.Row="4"
                      VerticalAlignment="Center">
                    Set the background color to:
                </CheckBox>
                <DropDownCustomColorPicker:CustomColorPicker 
                Grid.Row="4" Grid.Column="2"
                SelectedColor="{Binding BackgroundColor, Mode=TwoWay}"
                Width="50"
                HorizontalAlignment="Left"
                />
            </Grid>

            <!-- 34:  Sample text -->
            <TextBlock Grid.Row="34">Sample text:</TextBlock>
            <TextBlock Grid.Row="34" Grid.Column="2">
                <TextBlock.Foreground>
                    <SolidColorBrush Color="{Binding ResultingForegroundColor, Mode=OneWay}" />
                </TextBlock.Foreground>
                <TextBlock.Background>
                    <SolidColorBrush Color="{Binding ResultingBackgroundColor, Mode=OneWay}" />
                </TextBlock.Background>
            The brown fox jumps over the crazy dog, but my tailor is rich.
            </TextBlock>

            <!-- 36: Rule persistence -->
            <CheckBox IsChecked="{Binding Rule.IsPersistent, Mode=TwoWay}"
                  Grid.Row="36" Grid.ColumnSpan="3"
                  VerticalAlignment="Center">
                <CheckBox.Content>
                    <StackPanel>
                        <TextBlock TextWrapping="Wrap">
                        <Run>Rule is persistent.</Run>
                        </TextBlock>
                        <TextBlock TextWrapping="Wrap">
                        <Run>Please consider that a persistent rule involving a process with an ID may not be that useful.</Run>
                        </TextBlock>
                    </StackPanel>
                </CheckBox.Content>
            </CheckBox>

            <!-- 38: OK/Cancel -->
            <StackPanel Orientation="Horizontal"
                    Grid.Row="38" Grid.Column ="2"
                    VerticalAlignment="Bottom"
                    HorizontalAlignment="Right">
                <Button Content="OK"
                    Style="{StaticResource LargeButtonStyle}"
                    IsDefault="True"
                    Command="{Binding OKCommand}" />
                <Button Content="Cancel"
                    Style="{StaticResource LargeButtonStyle}"
                    Margin="20,0,0,0"
                    IsCancel="True"
                    Command="{Binding CancelCommand}" />

            </StackPanel>

        </Grid>
    </ScrollViewer>
</Window>
